package com.ang.juc.nt.list;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.IntStream;

public class CopyOnWriteListTest {

    public static void main(String[] args) throws InterruptedException {
        List<Integer> list = new CopyOnWriteArrayList<>();

        List<Thread> lt = new ArrayList<>();

        IntStream.range(0, 10).forEach(i->{
            Thread thread = new Thread(() -> {
                IntStream.range(0,100).forEach(j->{
                    list.add(1);
                });
            });

            thread.start();

            lt.add(thread);
        });

        for (Thread thread : lt) {
            thread.join();
        }

        System.out.println("size:" + list.size());
    }
}
